/**
 * App.jsx
 * Web应用启动主页
 *
 * created by qiuwei
 * version 1.0.0
 * 2016年03月15日
 */

import React from 'react';
import { connect } from 'react-redux';
import { replace } from 'react-router-redux';

import * as AppStyle from './App.less';

import { AUTHENTICATION } from '../../../constants/route';
import { logout } from '../actions/authentication';
import { reset } from '../actions/filter';

import moment from 'moment';
moment.locale('zh-cn');

class App extends React.Component {
    static propTypes = {
        name: React.PropTypes.string,
    };

    constructor(props) {
        super(props);
    }

    haneleLogout = () => {
        let { dispatch } = this.props;

        dispatch(logout());
        dispatch(replace(AUTHENTICATION));
        dispatch(reset());
    };

    render() {
        let { children, user } = this.props;

        return (
            <div className={AppStyle.app}>
                <div className='header'>
                    <div>
                        <span className='logo' />
                        { user && user.mobile &&
                        <span className='user'>
                            <span>{user.mobile}</span>
                            <button onClick={this.haneleLogout}>退出</button>
                        </span>
                        }
                    </div>
                </div>
                <div className='main'>
                    {children}
                </div>
            </div>
        );
    }
}

export default connect((state)=>state.authentication)(App);